package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.StudentInfo;
import service.StudentInfoService;

@WebServlet("/update")
public class UpdateServlet extends HttpServlet {

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("text/html;charset=utf-8");
		StudentInfoService studentInfoService = new StudentInfoService();
		
		StudentInfo studentInfo = new StudentInfo(); 
		studentInfo.setSid(Integer.parseInt(req.getParameter("sid")));
		studentInfo.setSname(req.getParameter("sname"));
		studentInfo.setSgender(req.getParameter("sgender"));
		studentInfo.setSage(Integer.parseInt(req.getParameter("sage")));
		studentInfo.setSaddress(req.getParameter("saddress"));
		studentInfo.setSemail(req.getParameter("semail"));
		int n = studentInfoService.updateStu(studentInfo);
		if(n > 0){
			resp.getWriter().print("<script>alert('修改成功');location.href='/StudentInfoManage/select';</script>");
		}else{
			resp.getWriter().print("<script>alert('修改失败');location.href='/StudentInfoManage/get?sid="+studentInfo.getSid()+"';</script>");
		}
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
}
